package com.aqiang.day0528_shop

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.design.widget.NavigationView
import android.support.v4.view.ViewPager
import android.view.PointerIcon
import android.widget.RelativeLayout
import com.aqiang.day0528_shop.main.adapter.VpAdapter
import com.aqiang.day0528_shop.user.contract.UserContract
import com.aqiang.lib_core.mvp.BaseActivity
import com.roughike.bottombar.OnTabSelectListener
import kotlinx.android.synthetic.main.activity_main.*
import org.greenrobot.greendao.annotation.Id

class MainActivity : BaseActivity<UserContract.LoginPresenter>() {
    override fun bindLatout(): Int {
        return R.layout.activity_main
    }

    override fun createPresenter() {

    }

    override fun initView(savedInstanceState: Bundle?) {

    }

    override fun initData() {
        initVp()
    }

    override fun initEvent() {
        vp_act_main.addOnPageChangeListener(object : ViewPager.OnPageChangeListener{
            override fun onPageScrollStateChanged(p0: Int) {

            }

            override fun onPageScrolled(p0: Int, p1: Float, p2: Int) {

            }

            override fun onPageSelected(p0: Int) {
                when(p0){
                    0 -> bb_act_main.selectedItemId = R.id.flish
                    1 -> bb_act_main.selectedItemId = R.id.type
                    2 -> bb_act_main.selectedItemId = R.id.find
                    3 -> bb_act_main.selectedItemId = R.id.car
                    else -> bb_act_main.selectedItemId = R.id.mine
                }
            }

        })
        bb_act_main.setOnNavigationItemSelectedListener {
            if(it.itemId == R.id.flish){
                vp_act_main.currentItem = 0
            }else if(it.itemId == R.id.type){
                vp_act_main.currentItem = 1
            }else if(it.itemId == R.id.find){
                vp_act_main.currentItem = 2
            }else if(it.itemId == R.id.car){
                vp_act_main.currentItem = 3
                tv_red.visibility = RelativeLayout.GONE
            }else{
                vp_act_main.currentItem = 4
            }
//            when(it.itemId){
//                R.id.flish -> vp_act_main.currentItem = 0
//                R.id.type -> vp_act_main.currentItem = 1
//                R.id.find -> vp_act_main.currentItem = 2
//                R.id.car -> vp_act_main.currentItem = 3
//                else -> vp_act_main.currentItem = 4
//            }
            return@setOnNavigationItemSelectedListener true
        }
    }

    fun initVp(){
        vp_act_main.adapter = VpAdapter(supportFragmentManager)
    }
}
